package net.xo68.destiny.core.lock;

import java.io.Serializable;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 分布式锁
 * @author wuxie
 * @version 2020-12-15
 */
public class DistributedLock  implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 尝试加锁
     */
    private final ReentrantLock tryLock = new ReentrantLock();
    /**
     * 尝试加锁等待
     */
    private final Condition timeoutCondition = tryLock.newCondition();

    /**
     * 锁信息
     */
    private DistributedLockInfo lockInfo;

    public DistributedLockInfo getLockInfo() {
        return lockInfo;
    }

    public void setLockInfo(DistributedLockInfo lockInfo) {
        this.lockInfo = lockInfo;
    }

    public ReentrantLock getTryLock() {
        return tryLock;
    }

    public Condition getTimeoutCondition() {
        return timeoutCondition;
    }

    @Override
    public String toString() {
        return "DistributedLock{" +
                "lockInfo=" + lockInfo +
                '}';
    }
}
